/**
 * Copyright [2012-2013] [Guðmundur Björn Birkisson]
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License. Copyright [2012-2013] [Guðmundur Björn Birkisson]
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * ---------------------------------------------------------------------------
 * 
 * Class name:  Tile
 * 
 * Description of class:
 * 
 * Class that represents one tile in a map.
 * 
 */

package karel.gamelogic.world;

import java.awt.Color;
import java.io.Serializable;

public class Tile implements Serializable {

    public enum Type {
        CLEAR, BLOCKED, EXIT, ROCK;
    }

    private Type type;
    private int nrOfRocks;

    public Tile(Type type) {
        this.type = type;
        this.nrOfRocks = 0;
    }
    
    public Tile(Type type, int nrOfRocks) {
        this.type = type;
        this.nrOfRocks = nrOfRocks;
    }
    
    public Type getType() {
        return type;
    }
    
    public int getNrOfRocks() {
        return nrOfRocks;
    }
    
    public void addRock() {
        if(type==Type.EXIT) {
            return;
        }
        type = Type.ROCK;
        nrOfRocks++;
    }
    
    public void removeRock() {
        if(!checkIfRock()) {
            return;
        }
        nrOfRocks--;
        if(nrOfRocks == 0) {
            type = Type.CLEAR;
        }
    }
    
    public boolean checkIfRock() {
        return type == Type.ROCK;
    }
    
    public static Color getColor(Tile.Type type) {
        switch(type) {
            case CLEAR:
                return Color.gray;
            case BLOCKED:
                return Color.darkGray;
            case EXIT:
                return new Color(0.0f, 0.5f, 0.0f);
            default:
                return new Color(1.0f, 0.0f, 0.0f);
        }
    }
}
